function checkDailyLife(){
	setupLabel();
	var totalScore=0;
	$(":radio:checked").each(function(){
		totalScore += parseInt($(this).data("score"));
	});
	$("#total").html(totalScore);
	if($(":radio:checked").length==0&&totalScore==0){
		$(".ability_result #level").attr("class","").addClass("result_level").text("暂无评级");
	}else if(totalScore <= 45){
		$(".ability_result #level").attr("class","").addClass("result_level3").text("3级-重度受损");
		$("#level").val(3);
	}else if(totalScore <= 60 && totalScore>45){
		$(".ability_result #level").attr("class","").addClass("result_level2").text("2级-中度受损");
		$("#level").val(2);
	}else if(totalScore < 100 && totalScore >60){	
		$(".ability_result #level").attr("class","").addClass("result_level1").text("1级-轻度受损");
		$("#level").val(1);
	}else if(totalScore == 100){
		$(".ability_result #level").attr("class","").addClass("result_level0").text("0级-能力完好");
		$("#level").val(0);
	}
}
function checkSpirit(){
	setupLabel();
	var totalScore=0;
	$(":radio:checked").each(function(){
		totalScore += parseInt($(this).data("score"));
	});
	$("#total").html(totalScore);
	
	if($(":radio:checked").length==0&&totalScore==0){
		$(".ability_result #level").attr("class","").addClass("result_level").text("暂无评级");
	}else if(totalScore <= 6 && totalScore >= 4){
		$(".ability_result #level").attr("class","").addClass("result_level3").text("3级-重度受损");
		$("#level").val(3);
	}else if( totalScore <= 3 && totalScore>= 2){
		$(".ability_result #level").attr("class","").addClass("result_level2").text("2级-中度受损");
		$("#level").val(2);
	}else if(totalScore == 1){
		$(".ability_result #level").attr("class","").addClass("result_level1").text("1级-轻度受损");
		$("#level").val(1);
	}else if(totalScore == 0){
		$(".ability_result #level").attr("class","").addClass("result_level0").text("0级-能力完好");
		$("#level").val(0);
	}
}
function checkCommun(){
	setupLabel();
	var totalScore=0;
	$(":radio:checked").each(function(){
		totalScore += parseInt($(this).data("score"));
	});
	$("#total").html(totalScore);
	var option_num='';
	var opVal = '';
	var arr = new Array();
	$(":radio:checked").each(function(){
		var $this = $(this);
		var index = $this.val();
		var hidden_val=$(":hidden[name=option_num_"+index+"]").val()+",";
		option_num += hidden_val;
		
		var tsVal=$(this).val();
		opVal= parseInt($("input[name='option_num_"+tsVal+"']").val());
		
		arr.push(opVal);
	});
	/*0能力完好：意识清醒，且视力和听力评为0或1，沟通评为0
		1轻度受损：意识清醒，但视力或听力中至少一项评为2，沟通评为1。
		2中度受损：意识清醒，但视力或听力中至少一项评为3，沟通评为2；//不含3
		或嗜睡，视力或听力评定为3及以下，沟通评定为2及以下。
		3重度受损：意识清醒或嗜睡，但视力或听力中至少一项评为4，或沟通评为3；或昏睡/昏迷
	 * */
	if($(":radio:checked").length==0&&totalScore==0){
		$(".ability_result #level").attr("class","").addClass("result_level").text("暂无评级");
	}else if(arr[0]==3001 && (arr[1]==3011 || arr[1]==3012 )&&( arr[2]==3021 || arr[2]==3022) && arr[3] == 3031){
		$(".ability_result #level").attr("class","").addClass("result_level0").text("0级-能力完好");
		$("#level").val(0);
	}else if ( arr[0]==3001 && ((arr[1]==3011 || arr[1]==3012 ||arr[1]==3013)
			||( arr[2]==3021 || arr[2]==3022 ||arr[2]==3023) && arr[3]==3032)){
		$(".ability_result #level").attr("class","").addClass("result_level1").text("1级-轻度受损");
		$("#level").val(1);
	}
	else if(arr[0]==3001 && ((arr[1]==3011 || arr[1]==3012 ||arr[1]==3013||arr[1]==3014)
			||(arr[2]==3021 || arr[2]==3022 ||arr[2]==3023))&& arr[3]==3033){
		$(".ability_result #level").attr("class","").addClass("result_level2").text("2级-中度受损");
		$("#level").val(2);
	}else if(arr[0]==3002 && ((arr[1]==3011 || arr[1]==3012 ||arr[1]==3013||arr[1]==3014)
			||(arr[2]==3021 || arr[2]==3022 ||arr[2]==3023))
//			||(arr[2]==3021 || arr[2]==3022 ||arr[2]==3023||arr[2]==3024))
			&& ( arr[3]==3031 ||arr[3]==3032)){
//		&& ( arr[3]==3031 ||arr[3]==3032 ||arr[3]==3033)){
		$(".ability_result #level").attr("class","").addClass("result_level2").text("2级-中度受损");
		$("#level").val(2);
	}
	else {
		$(".ability_result #level").attr("class","").addClass("result_level3").text("3级-重度受损");
		$("#level").val(3);
	}
}
 
function checkSociety(){
	setupLabel();
	var totalScore=0;
	$(":radio:checked").each(function(){
		totalScore += parseInt($(this).data("score"));
	});
	$("#total").html(totalScore);
	
	if($(":radio:checked").length==0&&totalScore==0){
		$(".ability_result #level").attr("class","").addClass("result_level").text("暂无评级");
	}else if(totalScore <= 20 && totalScore >= 14){
		$(".ability_result #level").attr("class","").addClass("result_level3").text("3级-重度受损");
		$("#level").val(3);
	}else if(8 <= totalScore <= 13 && totalScore >= 8){
		$(".ability_result #level").attr("class","").addClass("result_level2").text("2级-中度受损");
		$("#level").val(2);
	}else if(3 <= totalScore <= 7 && totalScore >= 3){
		$(".ability_result #level").attr("class","").addClass("result_level1").text("1级-轻度受损");
		$("#level").val(1);
	}else if(totalScore <= 2 &&totalScore >= 0){
		$(".ability_result #level").attr("class","").addClass("result_level0").text("0级-能力完好");
		$("#level").val(0);
	}
}
$(function(){
	$(".form-group").each(function(){
		var len_0=$(this).find(":radio").length;
		if(len_0!=0){
			var r_radio=$(this).find(":radio");
			r_radio.each(function(){
				$(this).click(function(){
					var len=$(this).parents(".form-group").find(":radio:checked").length;
					if(len!=0){
						$(this).parents(".form-group").find(".control-label").css("color","#666").removeClass("error_radio").find("span").remove();
					}
				})
			})
		}
		
	});
})
function save(){	
	var flag=false;
	$(".form-group").each(function(){
		var len_0=$(this).find(":radio").length;
		if(len_0!=0){
			var len=$(this).find(":radio:checked").length;
			if(len==0||len=="0"){
				zhyAlert("请检查是否有漏选！");
				var err_span=$("<span>请选择一项</span>");
				err_span.css({
					"color":"#f00",
					"position":"absolute",
					"right":"22px",
					"top":"25px"
				})
				$(this).find(".control-label").css({
					"color":"#f00",
					"position":"relative"
					}).addClass("error_radio").append(err_span);
			}else{
				$(this).find(".control-label").css("color","#666").removeClass("error_radio").find("span").remove();
			}
		}
		
	});
	var err_len= $(".error_radio").length;
	if(err_len==0){
		
		var level= $("#level").val();
		var ability_type = $("#ability_type").val();
		var member_id = $("#member_id").val();
		var server_station_code = $("#server_station_code").val();
		var age = $("#age").val();
		var name = $("#name").val();
		var postion_number = $("#postion_number").val();
		var reportId=$("#reportId").val();
		var option_num = "";
		$(":radio:checked").each(function(){
			var $this = $(this);
			var index = $this.val();
			option_num += $(":hidden[name=option_num_"+index+"]").val()+",";
		});
		$.ajax({
	       type: "POST",
	       async: false,
	       url : "../ability/save_ability",
	       data:{	
	    	   "option_num":option_num,
		       "ability_type":ability_type,
	           "level":level,
	           "member_id":member_id,
	           "server_station_code":server_station_code,
	           "reportId":reportId
	        }, 
	        error: function(request) {
	        	zhyAlert("保存失败");
	        },
	        success: function(data) {
	        	if(data.reportId!=0){
	        		$("#reportId").val(data.reportId);
	        	}
	        	var ability =$("#ability").val();
	        	zhyAlert("保存成功！");
	        	flag= true;
	        	if(ability_type==4&&ability=="live_manager"){
	        		//如果从入住跳转进来，在第四步提交的时候在跳转回入住
	        		success(ability,server_station_code,member_id,reportId);
	        	}else if(ability_type==4&&ability==""){
	        		window.location.href=$("#url").val()+"cloud-member/abilityManager/ability_details?member_id="+member_id+
	        		"&name="+name+"&age="+age+"&postion_number="+postion_number+"&serverStationCode="+server_station_code;
	        	}
	        }
	    });
	}
	return flag;
}
function success(ability,server_station_code,member_id,reportId){
		var url=$("#url").val()+"cloud-org/live/ability_evaluation?ability="+ability+
		"&station="+server_station_code+"&memberId="+member_id+"&reportId="+reportId;
		url=encodeURI(encodeURI(url));
		window.location.href=url;
}

function restart(){
	var flag=false;
	$(".form-group").each(function(){
		var len_0=$(this).find(":radio").length;
		if(len_0!=0){
			var len=$(this).find(":radio:checked").length;
			if(len==0||len=="0"){
				zhyAlert("请检查是否有漏选！");
				var err_span=$("<span>请选择一项</span>");
				err_span.css({
					"color":"#f00",
					"position":"absolute",
					"right":"22px",
					"top":"25px"
				})
				$(this).find(".control-label").css({
					"color":"#f00",
					"position":"relative"
					}).addClass("error_radio").append(err_span);
			}else{
				$(this).find(".control-label").css("color","#666").removeClass("error_radio").find("span").remove();
			}
		}
		
	});
	var err_len= $(".error_radio").length;
	if(err_len==0){
		var level= $("#level").val();
		var ability_type = $("#ability_type").val();
		var member_id = $("#member_id").val();
		var server_station_code = $("#server_station_code").val();
		var age = $("#age").val();
		var name = $("#name").val();
		var postion_number = $("#postion_number").val();
		var option_num = "";
		var reportId=$("#reportId").val();
		$(":radio:checked").each(function(){
			var $this = $(this);
			var index = $this.val();
			option_num += $(":hidden[name=option_num_"+index+"]").val()+",";
		});
		$.ajax({
	       type: "POST",
	       async: false,
	       url : "../abilityUpdate/restart",
	       data:{	
	    	   "option_num":option_num,
		       "ability_type":ability_type,
	           "level":level,
	           "member_id":member_id,
	           "server_station_code":server_station_code,
	           "reportId":reportId
	        }, 
	        error: function(request) {
	        	zhyAlert("保存失败");
	        },
	        success: function(data) {
	        	if(data.reportId!=0){
	        		$("#reportId").val(data.reportId);
	        	}
	        	zhyAlert("保存成功！");
	        	flag= true;
	        	if(ability_type==4){
	        		window.location.href=$("#url").val()+"cloud-member/abilityManager/ability_details?member_id="+member_id+
	        		"&name="+name+"&age="+age+"&postion_number="+postion_number+"&serverStationCode="+server_station_code;
	        	}
	        }
	    });
	}
	return flag;
}
//添加能力评估时点击日常生活下一步
function dailyLifeNext(){
//	alert("dailyLifeNext");
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../ability/ability_option_spirit",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//添加能力评估时点击精神状态下一步
function  spiritNext(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../ability/ability_option_commun",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//添加能力评估时点击感知觉与沟通下一步
function communNext(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../ability/ability_option_society",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}

//添加能力评估时点击精神状态上一步
function spiritPrevious(){
	var member_id = $("#member_id").val();
	var server_station_code = $("#server_station_code").val();
	var name = $("#name").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../ability/ability_option_dailylife",
		async: false,
		data:{
			"member_id":member_id,
			"server_station_code":server_station_code,
			"name":name
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//添加能力评估时点击感知觉与沟通上一步
function communPrevious(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../ability/ability_option_spirit",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}

//添加能力评估时点击社会参与上一步
function societyPrevious(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../ability/ability_option_commun",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//修改能力评估时点击日常生活下一步
function  spiritUpdateNext(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../abilityUpdate/ability_option_commun",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//修改能力评估时点击精神状态下一步
function dailyLifeUpdateNext(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../abilityUpdate/ability_option_spirit",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//修改能力评估时点击感知觉与沟通下一步
function communUpdateNext(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../abilityUpdate/ability_option_society",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//修改能力评估时点击社会参与上一步
function spiritUpdatePrevious(){
	var member_id = $("#member_id").val();
	var server_station_code = $("#server_station_code").val();
	var name = $("#name").val();
	$.ajax({
		type : "get",
		dataType: "html",
		url : "../abilityUpdate/ability_option_dailylife",
		async: false,
		data:{
			"member_id":member_id,
			"server_station_code":server_station_code,
			"name":name
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}
//修改能力评估时点击感知觉与沟通上一步
function communUpdatePrevious(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../abilityUpdate/ability_option_spirit",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}

//修改能力评估时点击精神状态上一步
function societyUpdatePrevious(){
	var member_id = $("#member_id").val();
	$.ajax({
		type : "post",
		dataType: "html",
		url : "../abilityUpdate/ability_option_commun",
		async: false,
		data:{
			"member_id":member_id
		},
		success : function(data) {
			$("#content_jsp").empty().html(data);
		}
	});
}

 
